package com.naxiang.cn.utils;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.BaseAdapter;

import com.bumptech.glide.Glide;
import com.naxiang.cn.naxiangvideoplay.R;

import java.util.List;

/**
 * 作者: 赵航
 * 创建时间: 2018/7/13 13:55
 * 描述:
 */
public class NaXiangAdapter extends BaseAdapter {

    private List<ItemBeen> mItemBeen;
    private int            mListImageWidth;
    private int            mListImageHeight;


    public NaXiangAdapter(List<ItemBeen> itemBeens, int listImageWidth, int listImageHeight) {
        this.mItemBeen=itemBeens;
        this.mListImageWidth = listImageWidth;
        this.mListImageHeight=listImageHeight;
    }

    @Override
    public int getCount() {
        return mItemBeen.size();
    }

    @Override
    public ItemBeen getItem(int position) {
        return mItemBeen.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        ViewHolder  holder=null;
        if (convertView==null){
            holder = new ViewHolder();
            convertView = LayoutInflater.from(parent.getContext()).inflate(R.layout.mo_naxiangvideoplay_item_layout,parent, false);
            holder.mListImage = (RoundImageView) convertView.findViewById(R.id.itemimage);

            //可以根据position对某Item进行高度设置
            AbsListView.LayoutParams layoutParams = new AbsListView.LayoutParams(mListImageWidth, mListImageHeight);//高度不能小于1,测试发现设置为0时不生效
            convertView.setLayoutParams(layoutParams);

            convertView.setTag(holder);
        }else {
            holder= (ViewHolder) convertView.getTag();
        }

             Glide.with(parent.getContext())
                        .load(mItemBeen.get(position).getImageUri())
                        .placeholder(R.drawable.loading)
                        .error(R.drawable.loading)
                        .into(holder.mListImage);

        return convertView;
    }

    public class ViewHolder{

        RoundImageView mListImage;

    }
}
